package asf.transitions
{
	import flash.events.EventDispatcher;
	
	import asf.core.Application;
	import asf.events.TransitionEvent;
	import asf.interfaces.ITransition;
	import asf.views.View;
	
	[Event( type="asf.events.TransitionEvent", name="transitionStart" )]
	[Event( type="asf.events.TransitionEvent", name="transitionComplete" )]
	
	public class Transition extends EventDispatcher
	{
		private var _nextView:View;
		private var _currentView:View;
		
		private var _trans:ITransition;
		private var _app:Application;
		
		public function Transition( p_nextView:View, p_currentView:View, p_app:Application, userTransition:ITransition )
		{
			super( null );
			
			_nextView = p_nextView;
			_currentView = p_currentView;
			
			_app = p_app;
			
			_trans = userTransition;
		}
		
		public function get nextView( ):View
		{
			return _nextView;
		}
		
		public function get currentView( ):View
		{
			return _currentView;
		}
		
		public function get hasCurrentView( ):Boolean
		{
			return _currentView != null;
		}
		
		public function init( ):void
		{
			if( _trans )
			{
				_trans.start( this );
			}
			else
			{
				notifyStart( );
				notifyComplete( );
			}
		}
		
		public function notifyStart( ):void
		{
			this.dispatchEvent( new TransitionEvent( TransitionEvent.TRANSITION_START ) );			
		}
		
		public function notifyComplete( ):void
		{
			this.dispatchEvent( new TransitionEvent( TransitionEvent.TRANSITION_COMPLETE ) );
		}
		
		public function dispose( ):void
		{
			if( _trans )
			{
				_trans.dispose( );
			}
			_currentView = null;
			_nextView = null;
		}
	}
}